#include <REGX52.h>
#include "Delay.h"

/*
 * @brief  获取独立按键键码
 * @param  无
 * @retval 按下按键的键码，范围0 ~ 4，无按键按下时返回值为0
 */
unsigned char Key() {
    unsigned char key_number = 0;
    if (P3_1 == 0) {
        Delay(20);  // 消抖
        while (P3_1 == 0) {}
        Delay(20);
        key_number = 1;
    }
    if (P3_0 == 0) {
        Delay(20);  // 消抖
        while (P3_0 == 0) {}
        Delay(20);
        key_number = 2;
    }
    if (P3_2 == 0) {
        Delay(20);
        while (P3_2 == 0) {}
        Delay(20);
        key_number = 3;
    }
    if (P3_3 == 0) {
        Delay(20);
        while (P3_3 == 0) {}
        Delay(20);
        key_number = 4;
    }
    return key_number;
}